package com.starsoft.trade.dao;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.starsoft.frame.core.orm.BaseDao;
import com.starsoft.frame.util.DateUtil;
import com.starsoft.trade.bean.TradePosition;

@Repository
public class TradePositionDao extends BaseDao<TradePosition, Integer>{
	
	public List<TradePosition> getPositions(Integer acountId, Date asofdate){
		String hql = "from TradePosition where id.acountId=?0 and id.asofdate=?1";
		return this.find(hql, acountId, asofdate);
	}
	
	public int deletePositions(Integer acountId, Date asofdate){
		String hql = "delete from TradePosition where  id.acountId = ?0 and id.asofdate=?1";
		return this.update(hql, acountId, asofdate);
	}
	
	public int deleteAcountAll(Integer acountId){
		String hql = "delete from TradePosition where  id.acountId = ?0";
		return this.update(hql, acountId);
	}
	
	public int deleteStatusAfter(Integer acountId, Date date) {
		String hql = "delete from TradePosition where  id.acountId = ?0 and id.asofdate>=?1";
		return update(hql, acountId, DateUtil.floorTime(date));
	}

	public int savePositions(List<TradePosition> positions){
		for(TradePosition position: positions){
			this.save(position);
		}
		return positions.size();
	}
}
